package com.foreknow.demo02;

import java.util.Random;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        boolean zhuce = false;//注册的表示为
        String answer = "y";
        Scanner input = new Scanner(System.in);
        String password1 = "";
        String information1 = "";
        boolean isLogin = false;//登录的标识位

        do {
            System.out.println("*******************************************");
            System.out.println("1.注册");
            System.out.println("2.登录");
            System.out.println("3.抽奖");
            System.out.println("*******************************************");

            System.out.println("请选择菜单：");
            int choice = input.nextInt();
            switch (choice){
                case 1:
                    int s = (int)(Math.random()*(9999-1000+1))+1000;//产生1000-9999的随机数
                    System.out.println("注册");
                    System.out.println("请填写个人注册信息：");
                    System.out.print("用户：");
                    information1 = input.next();
                    System.out.print("密码：");
                    password1 = input.next();
                    System.out.println("注册成功，请记好您 的会员号");
                    System.out.println("用户名    密码      会员号");
                    System.out.println("  " + information1+"    "+password1+"      "+s);
                    //将注册的标识位改为true
                    zhuce = true;
                    break;
                case 2:
                    if (zhuce){
                        for (int i = 0; i <3 ; i++) {
                            System.out.print("用户：");
                            String information = input.next();
                            System.out.print("密码：");
                            String password = input.next();
                            //判断登录的信息与注册时候的信息相同，字符串之间的比较一定要使用equals
                            if (information1.equals(information)&&password1.equals(password)){
                                System.out.println("欢迎您：" + information1);
                                isLogin = true;
                                break;
                            }else if (i<3){
                                System.out.println("您输入的用户名和密码不正确，还有" + (2-i) + "次机会");
                            }else {
                                System.out.println("3次错误的用户信息！！！！！！");
                            }
                        }
                    }else{
                        System.out.println("请先注册，然后才能登录！！！");
                    }

                    break;
                case 3:
                    System.out.println("抽奖");
                    break;
            }
           System.out.println("是否继续(y/n):");
            answer = input.next();
        }while (answer.equals("y"));
        if (answer.equals("n")){
            System.out.println("程序退出，谢谢使用！！！！");
        }

    }
}
